﻿using System;
using System.Web.Services;
using TripLOA.WebService.Serializable;

namespace TripLOA.WebService.Soap
{
    /// <summary>
    /// Ws relativo ai viaggi
    /// </summary>
    [WebService(Namespace = "http://triploa.cli.di.unipi.it/service/soap/", Name = "SoapTrip")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    //[ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class SoapTrip : System.Web.Services.WebService
    {
        private TripCore core;

        #region SoapTrip Constructors

        public SoapTrip()
        {
            core = TripCore.Istance();
        }

        #endregion

        #region SoapTrip Methods

        [WebMethod(EnableSession=true)]
        public WSTrip getTrip(int trip_id)
        {
            return core.getTrip(trip_id);
        }
        //Firma modificata con l'aggiunta di authToken per prove mobile
        [WebMethod(EnableSession=true)]
        public WSFullTrip GetTripDetails(string authToken,int tripID)
        {
            return core.GetTripDetails(authToken,tripID);
        }

        [WebMethod(EnableSession=true)]
        public WSBool BookTrip(string authToken, int tripID)
        {
            return core.BookTrip(authToken, tripID);
        }

        [WebMethod(EnableSession=true)]
        public WSBool CancelTrip(string authToken, int tripID)
        {
            return core.CancelTrip(authToken, tripID);
        }

        [WebMethod(EnableSession=true)]
        public WSBool AddTripToFavorites(string authToken, int tripID)
        {
            return core.AddTripToFavorites(authToken, tripID);
        }

        [WebMethod(EnableSession=true)]
        public WSBool RemoveTripFromFavorites(string authToken, int tripID)
        {
            return core.RemoveTripFromFavorites(authToken, tripID);
        }

        [WebMethod(EnableSession=true)]
        public WSBool IsBooked(string authToken, int tripID)
        {
            return core.IsBooked(authToken, tripID);
        }

        [WebMethod(EnableSession=true)]
        public WSBool IsInFavorites(string authToken, int tripID)
        {
            return core.IsInFavorites(authToken, tripID);
        }

        [WebMethod(EnableSession=true)]
        public WSTrip BookedTrips(string authToken, int start, int max)
        {
            return core.BookedTrips(authToken, start, max);
        }

        [WebMethod(EnableSession=true)]
        public WSTrip OfferedTrips(string authToken, int start, int max)
        {
            return core.OfferedTrips(authToken, start, max);
        }

        [WebMethod(EnableSession=true)]
        public WSTrip FavoritesTrips(string authToken, int start, int max)
        {
            return core.FavoritesTrips(authToken, start, max);
        }

        [WebMethod(EnableSession=true)]
        public WSInt CreateTrip(
            string authToken, string departureCoords, string arrivalCoords,
            DateTime departureDate, string generalNotes, byte freeSeats)
        {
            return core.CreateTrip(authToken, departureCoords, arrivalCoords, departureDate, generalNotes, freeSeats);
        }

        [WebMethod(EnableSession=true)]
        public WSInt SaveTrip(string authToken, Wrappers.FullTripInfo trip)
        {
            return core.SaveTrip(authToken, trip);
        }

        [WebMethod(EnableSession=true)]
        public WSBool DeleteTrip(string authToken, int tripId)
        {
            return core.DeleteTrip(authToken, tripId);
        }


        [WebMethod(EnableSession=true)]
        public WSTrip TripSearch(string authToken, string from, string to, DateTime fromDate, DateTime toDate, int start, int max)
        {
            return core.TripSearch(authToken, from, to, fromDate, toDate, start, max);
        }

        [WebMethod(EnableSession=true)]
        public WSBool RequestReservation(string authToken, int tripId, string fromCoords, string toCoords, byte seatsNo, int tolerance, string notes)
        {
            return core.RequestReservation(authToken, tripId, fromCoords, toCoords, seatsNo, tolerance, notes);
        }

        #endregion
    }
}
